<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>计划执行-计划调整信息</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>计划调整记录</span></div>
	<div id="qForm" class="mini-toolbar1"
		style="border-bottom: 0; padding: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 100%;">
					<div class="mb-20">
                        <span class="search-title search-ml20">节点名称</span><input id="nodeNames" name="nodeNames" class="mini-textbox search-200px">
                        <span class="search-title search-ml60">选择年月</span><div id="yearItem"></div>
                        <a class="add-botton search-ml60" onclick="list.search()">查询</a>
                        <a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
					</div>
				</td>
			</tr>
		</table>
	</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/planNodeAdjust/adjustListByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="false" showEmptyText="true" emptyText="暂无数据" alwaysShowEmptyText="true">
        <div property="columns">
            <!--<div type="checkcolumn" headerAlign="center" align="center"></div>-->
            <div type="indexcolumn" width="35" headerAlign="center" align="center">编号</div>
            <div field="planName" width="120" headerAlign="center" allowSort="false">计划名称</div>
            <!--<div field="businessName" width="120" headerAlign="center" allowSort="false">业务板块</div>-->
            <div field="nodeName" width="120" headerAlign="center" align="center" allowSort="false">节点名称</div>
            <!--<div field="nodePropertyValue" width="120" headerAlign="center" allowSort="false">节点性质</div>-->
            <div field="adjustTypeValue" width="120" headerAlign="center" align="center" allowSort="false">调整类型</div>
            <div field="beginDate" width="120" headerAlign="center" align="center" allowSort="false">计划起止时间</div>
            <div field="delayDate" width="120" headerAlign="center" align="center" allowSort="false">调整到时间</div>
            <!--<div field="adjustDeadline" width="120" headerAlign="center" allowSort="false">调整工期（天）</div>-->
            <div field="createDate" width="120" headerAlign="center" align="center" allowSort="false"  renderer="ondayRenderer" dateFormat="yyyy-MM-dd" >申请时间</div>
            <!--<div field="remark" width="120" headerAlign="center" allowSort="false">申请原因</div>-->
            <div field="auditState" width="120" headerAlign="center" align="center" allowSort="false" renderer="list.onGenderRenderer">审批状态</div>
            <!--<div field="auditResult" width="120" headerAlign="center" allowSort="false">审批结果</div>
            <div field="auditDate" width="120" headerAlign="center" allowSort="false" align="center" renderer="ondayRenderer" dateFormat="yyyy-MM-dd" >审批时间</div>-->
            <div name="action" width="200" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //list.init();
    //0 未提交 1审批中 、2、通过3、未通过
	var Genders = [{ id: 0, text: '未提交' },{ id: 1, text: '审批中' }, { id: 2, text: '通过'},{ id: 3, text: '未通过'}]; 

    var grid;
    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            common.changeYears();
            grid = mini.get("datagrid1");
            grid.load();
            grid.on("drawcell", function (e) {
                var column = e.column;

                if (column.name == "action") {
                	var aduitHtml,editHtml,delHtml;
                    console.log(e.row)
                    console.log(e.row.auditState)
                	if(e.row.auditState==0||e.row.auditState==3){
                		aduitHtml='<a class="revise-botton" href="javascript:list.aduit()">发送审批</a> ';
                		editHtml='<a class="revise-botton btn-bd" href="javascript:list.addOrEdit(\''+'edit'+'\')">编辑</a> ';
                		delHtml='<a class="del-botton btn-bd" onclick="list.remove()">删除</a>';
                	}else{
                		aduitHtml="";
                		editHtml="";
                		delHtml="";
                	}
                    e.cellHtml = aduitHtml+editHtml+'<a class="check-botton '+(aduitHtml&&editHtml&&delHtml?"btn-bd":"")+'" href="javascript:list.view()">查看</a>'+delHtml;
                }
                if(column.field=="beginDate"){
                    var dateText = "";
                    if(e.row.beginDate&&e.row.endDate){
                        dateText="至"
                    }
                    e.cellHtml = e.row.beginDate.substring(0,10)+dateText+e.row.endDate.substring(0,10);
                }
            })
        },
        onGenderRenderer: function (e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        },
        //    新增或编辑
        addOrEdit: function (opt) {
        	 mini.open({
	                url: "/program/planAdjustment/edit.html",
	                title: (opt=="edit"?"编辑":"新增")+"节点计划调整申请", width: 1100, height: 700,
	                onload: function () {
                       		var row = mini.get("datagrid1").getSelected();
	                        if(opt=="edit"){
		                        var data = {"planNodeId": row.planNodeId,"id":row.id,"state":opt};
	                        }else{
	                            var data = {"state":opt};
	                        }
	                        var iframe = this.getIFrameEl();
	                        iframe.contentWindow.view.SetData(data);
	                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        },
        //    填报记录
        view: function(){
            var row = mini.get("datagrid1").getSelected();
            if (row) {
                mini.open({
                    url: "/program/planAdjustment/view.html",
                    title: "计划调整信息", width: 1100, height: 700,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id,"planNodeId":row.planNodeId};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        mini.get("datagrid1").reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var years = mini.get("year").getValue();
            var mouths = mini.get("month").getValue();
            var allYear = years+'-'+mouths;
            var data = {
                "nodeName": mini.get("nodeNames").getValue(),
                "yearMonth": allYear
            };
            mini.get("datagrid1").load(data);
        },
        //重置
        reset:function(){
            mini.get("year").setValue(new Date().getFullYear());
            var years = mini.get("year").getValue();
            var endMonth = new Date().getMonth()+1;
            mini.get("month").setValue(endMonth);
            mini.get("nodeNames").setValue("");
            var now = new Date();
            var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
            mini.get("datagrid1").load({"yearMonth": time});
        }, //发送审批
        aduit: function(){
            var row = grid.getSelected();
            $.ajax({
				type : "post",
				url : "/loggerService/startPost",
				data : {"id":row.id,"formSign":"CDJHGLJHZXJHTZ_01","workFlowId":"CDJHGLJHZXJHTZSP","jumpUrl":"/program/planAdjustment/workflow.html?id="+row.id+"&planNodeId="+row.planNodeId,"url":"/act/taskApi/start","exampleEntity":"planNodeAdjust"},
				success : function(msg) {
					if(msg.message==="ok"){
						list.updateAuditState(row.id);
					}
				}
			});
		}, //改变数据状态
        updateAuditState: function(id){
            $.ajax({
				type : "post",
				url : "/planNodeAdjust/edit",
				data : {"id":id},
				success : function(msg) {
		            mini.get("datagrid1").load()
				}
			});
		}, //    删除
        remove: function () {
            var row = grid.getSelected();
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: "/planNodeAdjust/del",
                            type : "post",
                            data:{"id":row.id},
                            success: function (text) {
                                if (text.state) {
                                    grid.reload();
                                } else {
                                    mini.showMessageBox({
                                        showModal: false,
                                        width: 250,
                                        title: "提示",
                                        iconCls: "mini-messagebox-warning",
                                        message: text.message,
                                    });

                                }
                            }
                        });
                    }
                });
            } else {
                alert("请选中一条记录");
            }
        }
    };
    list.init();
</script>
</body>
</html>